/*
 * NetworkEventData.cpp
 *
 *  Created on: Sep 13, 2011
 *      Author: erudhes
 */
#include "NetworkEventData.h"

NetworkEventData::NetworkEventData(): mDataType((DataType)htonl((int)INVALID)), mX(htonl(-1)), mY(htonl(-1))
{
	memset(mLevel, 0, 256);
}

NetworkEventData::NetworkEventData(NetworkEventData::DataType dataType, int x, int y, const wxChar* level): mDataType((DataType)htonl((int)dataType)), mX(htonl(x)), mY(htonl(y))
{
	// Convert the string to UTF8 to get rid of endian-ness
	wxString strLevel(level);
	const wxCharBuffer charBuffer = strLevel.ToUTF8();
	const char* tempLevel = charBuffer.data();

	memset(mLevel, 0, 256);
	strcpy(mLevel, tempLevel);
}

NetworkEventData::NetworkEventData(NetworkEventData::DataType dataType, const wxPoint& position, const wxString& level): mDataType((DataType)htonl((int)dataType)), mX(htonl(position.x)), mY(htonl(position.y))
{
	// Convert the string to UTF8 to get rid of endian-ness
	const wxCharBuffer charBuffer = level.ToUTF8();
	const char* tempLevel = charBuffer.data();

	memset(mLevel, 0, 256);
	strcpy(mLevel, tempLevel);
}

NetworkEventData::NetworkEventData(char* buffer)
{
	mDataType = *((DataType*)(buffer));
	buffer += sizeof(DataType);
	mX = *((int*)(buffer));
	buffer += sizeof(int);
	mY = *((int*)(buffer));
	buffer += sizeof(int);
	memcpy(mLevel, buffer, 256);
}

